<template>
    <div class="article-list">
        <div class="article-list-card">
            <div class="article-list-height">
                <router-link :to="{name:'article-add-nosave'}">
                    <Button class="article-list-rightBtn" type="primary" size="large"><Icon type="plus-round"></Icon>新增文章</Button>
                </router-link>
            </div>
            <i-table height="680" stripe :columns="columns" :data="data"></i-table>
            <div style="padding: 15px;">
                <Page @on-page-size-change="changeTiao" @on-change="changePage" :current="index" :total="total" show-elevator show-sizer :placement="'top'" :page-size="page_con" :page-size-opts="[10, 15, 20, 30, 40, 50]"></Page>
            </div>
        </div>
        <Modal v-model="modal2" width="360">
            <p slot="header" style="color:#f60;text-align:center">
                <Icon type="information-circled"></Icon>
                <span>删除确认</span>
            </p>
            <div style="text-align:center">
                <p>是否继续删除？</p>
            </div>
            <div slot="footer">
                <Button type="error" size="large" long :loading="modal_loading" @click="del">删除</Button>
            </div>
        </Modal>
        <Modal v-model="modal3" width="360">
            <p slot="header" style="color:#f60;text-align:center">
                <Icon type="information-circled"></Icon>
                <span>显示确认</span>
            </p>
            <div style="text-align:center">
                <p>是否确认显示？</p>
            </div>
            <div slot="footer">
                <Button type="error" size="large" long :loading="modal_loading" @click="shownow">显示</Button>
            </div>
        </Modal>
    </div>
</template>
<script>
    export default {
        name:"article-list",
        data(){
            return{
                columns:[
                    {
                        title: '序号',
                        type: 'index',
                        width: 60,
                        align:"center",
                    },
                    {
                        title: '分类',
                        key: 'type',
                        align:"center",
                        width: 100,
                        render:(h,params)=>{
                            if(params.row.type ==1){
                                return '新闻'
                            }
                            else if(params.row.type ==2){
                                return '公告'
                            }
                            else{
                                return '帮助中心'
                            }
                        }
                    },
                    {
                        title: '标题',
                        key: 'title',
                        align:"center",
                    },
                    {
                        title: '内容',
                        key: 'content',
                        align:"center",
                        render:(h,params)=>{
                            return h('span',{
                                domProps: {
                                    innerHTML: params.row.content
                                },
                                style:{
                                    display: '-webkit-box',
                                    overflow: 'hidden',
                                    height:'40px'

                                }

                            })
                        }
                    },
                    // {
                    //     title: '图标',
                    //     key: 'articleimg',
                    //     align:"center",
                    //     width:100,
                    //     render:(h,params)=>{
                    //         if(params.row.articleimg==""){
                    //             return "暂无"
                    //         }else{
                    //             return h("div",{
                    //                 style:{
                    //                     cursor: "pointer",
                    //                 },
                    //     on:{
                    //         mouseover:(e)=>{
                    //             this.$store.commit("setImgData",{
                    //                 src:e.target.src||e.target.getElementsByTagName("img")[0].src||"",
                    //                 x:e.x+50+"px",
                    //                 y:e.y-60+"px",
                    //             })
                    //         },
                    //         mousemove:(e)=>{
                    //             this.$store.commit("setImgData",{
                    //                 src:e.target.src||e.target.getElementsByTagName("img")[0].src||"",
                    //                 x:e.x+50+"px",
                    //                 y:e.y-60+"px",
                    //             })
                    //         },
                    //         mouseout:(e)=>{
                    //             this.$store.commit("setImgData",{
                    //                 src:"",
                    //                 x:"0px",
                    //                 y:"0px",
                    //             })
                    //         }
                    //     }
                    // },[
                    //                 h("img",
                    //                     {
                    //                         attrs:{
                    //                             src:params.row.articleimg
                    //                         },
                    //                         style:{
                    //                             width:"42px",
                    //                             height:"42px",
                    //                             borderRadius:"4px",
                    //                             margin:"0px auto",
                    //                             display:"block",
                    //                         },
                    //                     })
                    //             ])
                    //         }
                    //     }
                    // },
                    // {
                    //     title: '分类',
                    //     key: 'catname',
                    //     align:"center",
                    // },
                    {
                        title: '是否显示',
                        key: 'status',
                        align:"center",
                        width: 100,
                        render:(h,params)=>{
                            return h("div",
                                [
                                    h("Icon",{
                                        props:{type: params.row.status==1?'eye':'eye-disabled'}
                                    }),
                                    h("span",params.row.status==1?' 显示':' 隐藏')
                                ]
                            )
                        }
                    },
                    // {
                    //     title: '排序号',
                    //     key: 'id',
                    //     align:"center",
                    //     width: 100,
                    // },

                    {
                        title: '创建时间',
                        key: 'add_time',
                        align:"center",
                        render:(h,params)=>{
                            return this.timeFormat(params.row.add_time)
                        }
                    },
                    {
                        title: '操作',
                        key: 'action',
                        align: 'center',
                        width: 250,
                        render: (h, params) => {
                            return h('ButtonGroup', [
                                h('Button', {
                                    props: {
                                        type: 'warning',
                                    },
                                    on: {
                                        click: () => {
                                            this.tiao(params.index)
                                        }
                                    }
                                },"修 改"),
                                h('Button', {
                                    props: {
                                        type: 'error',
                                    },
                                    on: {
                                        click: () => {
                                            this.show(params.index)
                                        }
                                    }
                                }, '显 示'),
                                h('Button', {
                                    props: {
                                        type: 'error',
                                    },
                                    on: {
                                        click: () => {
                                            this.remove(params.index)
                                        }
                                    }
                                }, '删 除')
                            ]);
                        }
                    },
                ],
                data:[],
                total:0,
                index:1,
                page_con:15,
                modal2:false,
                modal3:false,
                doIndex:0,//操作的下标
                modal_loading:false,
            }
        },
        activated(){
            this.getArticleList()
        },
        methods:{
            getArticleList(){
                this.getJsonData("Art/index/",{num:this.page_con,page:this.index})
                    .then((res)=>{
                        this.data=res.arts
                        this.total=parseInt(res.count)
                    })
            },
            changePage(n){
                this.index=n
                this.getArticleList()
            },
            changeTiao(num){
                this.page_con=num
                this.index=1
                this.getArticleList()
            },
            remove(n){
                this.doIndex=n
                this.modal2=true
            },
            show(n){
                this.doIndex=n
                this.modal3=true
            },
            del(){
                this.modal_loading = true;
                this.getJsonData("Art/deleteArt",{id:this.data[this.doIndex].id},true)
                    .then((res)=>{
                        this.getArticleList()
                        this.modal_loading = false;
                        this.modal2 = false;
                        this.$Message.success('删除成功');
                    }).catch((res)=>{
                    this.modal_loading = false;
                    this.modal2 = false;
                })
            },
            shownow(){
                this.modal_loading = true;
                this.getJsonData("Art/runArtStatus",{id:this.data[this.doIndex].id},true)
                    .then((res)=>{
                        this.getArticleList()
                        this.modal_loading = false;
                        this.modal3 = false;
                        this.$Message.success('操作成功');
                    }).catch((res)=>{
                    this.modal_loading = false;
                    this.modal3 = false;
                })
            },
            tiao(n){
                this.$router.push({name:"article-add-nosave",query:{isEdit:true,id:this.data[n].id}})
            },
        }
    }
</script>
<style lang="less">
    @import "./article-list";
</style>
